<!-- 维保 -->
<template>
	<view style="height: 100vh; background-color: #FFFFFF;">
		<u-navbar title-color="#FFFFFF" height="48" back-icon-color="#FFFFFF" :border-bottom="false" :is-fixed="true" :title="'维保记录'">
			<view class="navbar-right" slot="right">
				<u-icon name="plus" size="38" @click="addMaintenance"></u-icon>
			</view>
		</u-navbar>
		<uni-list>
			<uni-list-item direction="column" v-for="(item, index) in MaintenanceList" link :to="'/pages/index/equipment/Maintenance/info?ucId='+item.ucId"
			 :key="item.ucId">
				<!-- 自定义 body -->
				<text slot="body" class="slot-box slot-text" style="line-height: 22px;">
					<text>设备名称:{{item.equipmentName}}</text></br>
					<text style="font-size: 14px;">所属企业:{{item.enterpriseName}}</text></br>
					<text style="font-size: 14px;">维保状态:{{item.maintenanceStatus|maintenanceStatus}}</text>
				</text>
			</uni-list-item>
		</uni-list>

		<u-loadmore :status="status" :icon-type="iconType" :load-text="loadText" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				equipmentId: null,
				MaintenanceList: [],
				pageNum: 0,
				finished: false,
				status: 'loadmore',
				iconType: 'flower',
				loadText: {
					loadmore: '轻轻上拉',
					loading: '努力加载中',
					nomore: '没有更多数据了'
				}
			}
		},
		onLoad(e) {
			console.log(e)
			this.equipmentId = e.ucId || null
		},
		onShow() {
			this.initView()
		},
		methods: {
			initView(val) {
				this.MaintenanceList = []
				this.pageNum = 0
				this.getEquipmentMaintenancePage()
			},
			//获取设备分页信息数据
			getEquipmentMaintenancePage() {
				this.pageNum++
				let _this = this
				return new Promise((resolve, reject) => {
					_this.utils.request("/api/app/maintenance/getEquipmentMaintenancePage", {
						pageNum: this.pageNum,
						pageSize: 10,
						deleted: false,
						equipmentId: this.equipmentId
					}, "post", "app", true).then(res => {
						console.log(res.data)
						_this.MaintenanceList.push(...res.data.list)
						_this.finished = (res.data.pageNum >= res.data.pages);
						if (_this.finished) {
							_this.status = 'nomore';
						}
						resolve(res)
					}).catch(error => {
						reject(error)
					})
				})
			},
			onReachBottom() {
				if (this.finished) return;
				this.status = 'loading';
				this.getEquipmentMaintenancePage().then(res => {
					if (this.finished) this.status = 'nomore';
					else this.status = 'loading';
				}).catch(error => {
					this.status = 'nomore';
				})
			},
			addMaintenance() {
				uni.navigateTo({
					url: "/pages/index/equipment/Maintenance/edit?ucId=" + this.equipmentId
				})
			}
		}
	}
</script>

<style>
	.navbar-right {
		margin-right: 24rpx;
		display: flex;
	}
</style>
